package com.bestv.bsr.core.validate;

import org.apache.commons.lang3.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 自定义验证注解
 *
 * @author taojiacheng
 */
public class TvIdValidator implements ConstraintValidator<TvId, String> {


    @Override
    public void initialize(TvId constraintAnnotation) {
    }

    @Override
    public boolean isValid(String tvId, ConstraintValidatorContext context) {
        if (StringUtils.isNotBlank(tvId)) {
            String[] tvIds = tvId.split("\\$");
            return tvIds.length == 3;
        }
        return true;
    }
}
